// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
  console.log(event);
  try {
    let res1 = await db.collection('questions')
    .aggregate()
    .sample({
      size: 100
    })
    .limit(100)
    .end()

    // let res2 = await db.collection('questions')
    // .aggregate()
    // .match({
    //   typecode: '02'
    // })
    // .sample({
    //   size: 5
    // })
    // .end()

    // let res5 = await db.collection('questions')
    // .aggregate()
    // .match({
    //   typecode: '05'
    // })
    // .sample({
    //   size: 2
    // })
    // .end()


    // console.log(res1,res2);
    let arr1 = res1.list;
    // let arr2 = res2.list;
    // let arr5 = res5.list;
    // let items = arr1.concat(arr2,arr5);
    let items = arr1;

    return {
      list: items
    }

  } catch(e) {
    console.error(e)
  }
}